﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using WalkingTec.Mvvm.Core;
using System.Text.Json.Serialization;
using nERP.Model;
using nERP.Model.Bas;
using nERP.Model.So;
using nERP.Model.Wms;

namespace nERP.Model.So
{
    /// <summary>
    /// 销售退货
    /// </summary>
	[Table("SaleReturn")]
    [SoftKey(nameof(SaleReturn.SaleReturnCode))]
    [Display(Name = "_Model.SaleReturn")]
    public class SaleReturn : BasePoco,IPersistPoco,ITenant,IWorkflow
    {
        [Display(Name = "_Model._SaleReturn._SaleReturnCode")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("退货单号")]
        [Required(ErrorMessage = "Validate.{0}required")]
        [CanNotEdit]
        public string SaleReturnCode { get; set; }
        [Display(Name = "_Model._SaleReturn._Customer")]
        [Comment("客户")]
        [NotMapped]
        public Customer Customer { get; set; }
        [Display(Name = "_Model._SaleReturn._Customer")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Required(ErrorMessage = "Validate.{0}required")]
        [Comment("客户")]
        public string CustomerId { get; set; }
        [Display(Name = "_Model._SaleReturn._InvoicesDate")]
        [Comment("单据日期")]
        public DateTime? InvoicesDate { get; set; }
        [Display(Name = "_Model._SaleReturn._MakeUser")]
        [Comment("制单人")]
        [NotMapped]
        public FrameworkUser MakeUser { get; set; }
        [Display(Name = "_Model._SaleReturn._MakeUser")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("制单人")]
        public string MakeUserId { get; set; }
        [Display(Name = "_Model._SaleReturn._InvoicesFile")]
        [Comment("单据附件")]
        public List<SaleReturnInvoicesFile> InvoicesFile { get; set; }
        [Display(Name = "_Model._SaleReturn._SaleOutWarehouse")]
        [Comment("销售出库")]
        [NotMapped]
        public SaleOutWarehouse SaleOutWarehouse { get; set; }
        [Display(Name = "_Model._SaleReturn._SaleOutWarehouse")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Required(ErrorMessage = "Validate.{0}required")]
        [Comment("销售出库")]
        public string SaleOutWarehouseId { get; set; }
        [Display(Name = "_Model._SaleReturn._Sale")]
        [Comment("销售单号")]
        [NotMapped]
        public Sale Sale { get; set; }
        [Display(Name = "_Model._SaleReturn._Sale")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Required(ErrorMessage = "Validate.{0}required")]
        [Comment("销售单号")]
        public string SaleId { get; set; }
        [Display(Name = "_Model._SaleReturn._Remark")]
        [StringLength(256, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("备注")]
        public string Remark { get; set; }
        [Display(Name = "_Model._SaleReturn._Status")]
        [Comment("单据状态")]
        public StatusTypeEnum? Status { get; set; }
        [Display(Name = "_Model._SaleReturn._TotalPrice")]
        [Comment("总金额")]
        public decimal? TotalPrice { get; set; }
        [Display(Name = "_Model._SaleReturn._TotalPrice1")]
        [Comment("已结金额")]
        public decimal? TotalPrice1 { get; set; }
        [Display(Name = "_Model._SaleReturn._TotalPrice2")]
        [Comment("未结金额")]
        public decimal? TotalPrice2 { get; set; }
        [Display(Name = "_Model._SaleReturnDetail._SaleReturn")]
        [InverseProperty("SaleReturn")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.So.SaleReturnDetail.SaleReturnId))]
        public List<SaleReturnDetail> SaleReturnDetail_SaleReturn { get; set; }
        [Display(Name = "_Model._SaleReturnInWarehouse._SaleReturn")]
        [InverseProperty("SaleReturn")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.SaleReturnInWarehouse.SaleReturnId))]
        public List<SaleReturnInWarehouse> SaleReturnInWarehouse_SaleReturn { get; set; }
        [Display(Name = "_Model._SaleReturnInWarehouseDetail._SaleReturn")]
        [InverseProperty("SaleReturn")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.SaleReturnInWarehouseDetail.SaleReturnId))]
        public List<SaleReturnInWarehouseDetail> SaleReturnInWarehouseDetail_SaleReturn { get; set; }
        [Display(Name = "_Model._SaleReturn._IsValid")]
        [Comment("是否有效")]
        [Required(ErrorMessage = "Validate.{0}required")]
        public bool IsValid { get; set; } = true;
        [StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
        public string TenantCode { get; set; }

	}
    public class SaleReturnInvoicesFile : TopBasePoco, ISubFile
    {
        public Guid SaleReturnId { get; set; }
        public SaleReturn SaleReturn { get; set; }
        public Guid FileId { get; set; }
        public FileAttachment File { get; set; }
        public int Order { get; set; }
    }

}
